package site.shihuan.helpdesk.ticket.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.shihuan.helpdesk.common.model.JwtUser;
import site.shihuan.helpdesk.common.model.RestResult;
import site.shihuan.helpdesk.common.model.RestResultUtils;
import site.shihuan.helpdesk.security.context.UserContext;
import site.shihuan.helpdesk.ticket.manager.TicketReplyManager;
import site.shihuan.helpdesk.ticket.model.po.TktReplyPO;

/**
 * 工单回复
 *
 * @author 周世焕
 * @Date 2021/4/7 21:43
 */
@RestController
@RequestMapping("/v1/ticket/reply")
public class TicketReplyController {

    @Autowired
    private TicketReplyManager replyManager;

    /**
     * 获取工单回复
     * @param ticketId
     * @return
     */
    @GetMapping("list")
    public RestResult findReplyList(@RequestParam String ticketId) {
        return RestResultUtils.success(replyManager.findReplyList(ticketId));
    }

    /**
     * 修改最终解决方案
     * @param ticketId
     * @return
     */
    @PostMapping("final")
    public RestResult saveFinalReply(@RequestParam String ticketId, @RequestParam String reply) {
        replyManager.saveFinalReply(UserContext.getTenantId(),ticketId,reply);
        return RestResultUtils.success();
    }

    @DeleteMapping
    public RestResult deleteReply(@RequestParam String replyId) {
        replyManager.deleteReply(UserContext.getTenantId(),replyId);
        return RestResultUtils.success();
    }

    @PostMapping
    public RestResult saveReply(@RequestBody TktReplyPO replyPO) {
        JwtUser user = UserContext.getUser();
        replyPO.setTenantId(user.getTenantId());
        replyPO.setUserId(user.getUid());
        return RestResultUtils.success(replyManager.saveReply(replyPO));
    }
}
